/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package library.command;

import java.util.List;
import library.book.Book;
import library.control.ControlProvider;
import library.control.IControlBook;

/**
 *
 * @author MonStar
 */
public class RemoveCommand implements ICommand {
    private String REMOVE = "remove";

    @Override
    public String name() {
        return REMOVE;
    }

    @Override
    public void execute(String... args) {
        Boolean flag = false;
        List<IControlBook> listControlBook = ControlProvider.getControl().getListControlBook();
        for (IControlBook controlBook : listControlBook) {
            for (Book book : controlBook.getListBooks()) {
                String[] infoBook = book.infoBook();
                for (String field : infoBook) {
                    //if (field.equals(text)) {
                    if (field.equals("Название книги")) {
                        controlBook.removeBook(book);
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    break;
                }
            }
        }
    }
}
